Subscribe Us

Responsive Advertisement

Advertisement

1634C OKEA codeforces solution in cpp

 

1634C OKEA codeforces solution in cpp

by ujjal roy


#include<bits/stdc++.h>

using namespace std;

int main()

{

    int t,n,k,i,e,o,r;

    cin>>t;

    while(t--)

    {

        e=2;

        o=1;

        cin>>n>>k;

        r=n*k;

        if(k==1)

        {

            cout<<"YES"<<endl;

            for(i=1;i<=n*k;i++) cout<<i<<endl;;


        }



        else

        {

            if(n%2!=0) cout<<"NO"<<endl;

            else

            {

                cout<<"YES"<<endl;

                while(o<r)

                {

                    for(i=1;i<=k;i++)

                    {

                        cout<<o<<" ";

                        o+=2;

                        if(o>r) break;

                    }

                    cout<<endl;

                }


                while(e<=r)

                {

                    for(i=1;i<=k;i++)

                    {

                        cout<<e<<" ";

                        e+=2;

                        if(e>r) break;

                    }

                    cout<<endl;

                }



            }

        }


    }



    return 0;

}


Post a Comment

0 Comments